Skip to content

Conversation

AlecVercruysse
Copy link
Contributor

I ran the example code in a Scala 3.6.3 repl to understand the behavior of the underscore. The interpreter warns that the syntax is no longer supported:

scala> val numbers = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
val numbers: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

scala> val numberFunc = numbers.foldLeft(List[Int]())
val numberFunc: ((List[Int], Int) => List[Int]) => List[Int] = Lambda$1752/0x0000008001565820@a4dcede

scala> numberFunc((xs, x) => xs :+ x*x)
val res1: List[Int] = List(1, 4, 9, 16, 25, 36, 49, 64, 81, 100)

scala> val numberFunc = numbers.foldLeft(List[Int]()) _
1 warning found
-- Warning: ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1 |val numberFunc = numbers.foldLeft(List[Int]()) _
  |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |                 The syntax `<function> _` is no longer supported;
  |                 you can simply leave out the trailing ` _`
val numberFunc: ((List[Int], Int) => List[Int]) => List[Int] = Lambda$1786/0x00000080015b59c0@2634d000

So I propose providing separate tabs for Scala 2 vs Scala 3.

Copy link
Member

@adpi2 adpi2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@som-snytt som-snytt merged commit 40565ef into scala:main Feb 22, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants